<template>
  <div class="nav">
    <el-menu
  :default-active="activeIndex2"
  class="el-menu-demo"
  mode="horizontal"
  @select="handleSelect"
  background-color="#545c64"
  text-color="#fff"
  active-text-color="#ffd04b">
  <el-menu-item index="1" @click="home">首页</el-menu-item>
  <el-menu-item index="3" disabled>联系我们</el-menu-item>
  <el-menu-item index="4" @click="my">我的订单</el-menu-item>
  <el-submenu index="5">
    <template slot="title">我的信息</template>
    <el-menu-item index="2-1" @click="person">个人信息</el-menu-item>
    <el-menu-item index="2-2" @click="logout">退出登录</el-menu-item>
  </el-submenu>
  </el-menu>
    </div>
</template>

<script>

  export default {

    data() {
      return {
        activeIndex2: '1'
      };
    },
    methods: {
      handleSelect(key, keyPath) {
        console.log(key, keyPath);
      },
      home(){
        if (this.$route.path !== '/home'){
        this.$router.push('/home');
          }
      },
      person(){
        if (this.$route.path !== '/my'){
        this.$axios.post('/customer/selectCname',{

            cname:JSON.parse(localStorage.getItem('user')).cname,
            },
            {
              headers:{
                "token":JSON.parse(localStorage.getItem('user')).token
              } 
              })
            .then(res =>{
                this.customer = res.data.data;
                console.log("66")
                console.log(this.customer)
                console.log("66")

                    this.$router.push({
                    name: 'my',
                    params: {
                          customer:this.customer
                        }
                      });
                    
              })
            }
      },
      my(){
        if (this.$route.path !== '/myorder'){
        this.$router.push('/myorder');
          }
      },
      logout() {
      localStorage.removeItem("user")
      this.$router.push('/')
      this.$message.success("退出成功")
    }
    }
  }
</script>
<style>
.nav{
  /* position: relative; */
  width: 100%;
}
.el-icon-user{
  margin-right: 10px;
  font-size: 40px;
}


</style>